package com.pureut.storage.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.AllotManagementDetail;
import com.pureut.storage.dto.AllotManagementDetailDto;
import com.pureut.storage.mapper.AllotManagementDetailMapper;
import com.pureut.storage.service.AllotManagementDetailService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: CM
 * @date: 2023/2/14  14:12
 */
@Service
public class AllotManagementDetailServiceImpl extends ServiceImpl<AllotManagementDetailMapper, AllotManagementDetail> implements AllotManagementDetailService {

    @Resource
    AllotManagementDetailMapper allotManagementDetailMapper;

    /**
     * 调拨单明细列表
     * @param docNum
     * @return
     */
    @Override
    public List<AllotManagementDetailDto> getList(String docNum) {

        //获取单据状态字典数据
        List<SysDictData> statusArray = DictUtils.getDictCache("allot_management_detail_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        List<AllotManagementDetailDto> allotManagementDetailDtoList=allotManagementDetailMapper.getAllotManagementDetailList(docNum);
        for (AllotManagementDetailDto allotManagementDetailDto : allotManagementDetailDtoList) {
            allotManagementDetailDto.setMaterialStatusDict(allotManagementDetailDto.getMaterialStatus());
            allotManagementDetailDto.setMaterialStatus(statusMap.get(allotManagementDetailDto.getMaterialStatus()));
        }

        return allotManagementDetailDtoList;
    }
}
